package demo;

import java.util.List;

import javanet.exception.JavaNETException;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

@Stateless
@LocalBean
public class ProjectFacade {

	@EJB
	private DemoDataStore dataStore;
	
	public ProjectFacade() {
	}

	public void saveProject(Project project) throws JavaNETException {
		dataStore.save(project);
		System.out.println("created project: " + project);
	}

	public List<Project> findAllProjects() {
		return dataStore.getProjectList();
	}
	
	public Project findProjectById(Long id)
	{
		long searchId = id;
		System.out.println("find project with id: " + id);
		List<Project> projectList = dataStore.getProjectList();
		for (Project p : projectList) {
			if (p.getId() == searchId)
			{
				return p;
			}
		}
		return null;
	}

	public Project addMilestoneToProject(Project project, Milestone milestone) {
		System.out.println("add milestone: " + project + milestone);
		project.addMilestone(milestone);
		return dataStore.save(project);
	}

}
